package com.yoomiito.app.base

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import cn.droidlover.xdroidmvp.net.ApiException
import cn.droidlover.xdroidmvp.net.ApiSubscriber
import cn.droidlover.xdroidmvp.net.XApi
import com.yoomiito.app.model.bean.UserInfo
import com.yoomiito.app.net.YmApi

class BaseFragmentViewModel: ViewModel() {
    val getUserInfo : MutableLiveData<UserInfo> by lazy {
        MutableLiveData<UserInfo>().also {
            userInfo()
        }
    }
    fun userInfo() {
        YmApi.getYmService()
                .userInfo
                .compose(XApi.getApiTransformerData())
                .compose(XApi.getScheduler())
                .subscribe(object : ApiSubscriber<UserInfo?>() {
                    override fun onSuccess(userInfo: UserInfo?) {
                        getUserInfo.postValue(userInfo)
                    }

                    override fun onFail(error: ApiException) {

                    }
                })
    }
}